import { menu } from "../../decorator";
import shapEllipse from "../shap/shapEllipse";
import baseColorShap from "./base/baseColorShap";

const { ccclass, property, disallowMultiple, executeInEditMode, requireComponent } = cc._decorator;

@ccclass
@menu(__filename)
@disallowMultiple()
@executeInEditMode()
@requireComponent(shapEllipse)
export default class colorShapEllipse extends baseColorShap {

    constructor() {
        super();

        this._needLineJoin = true;
        this._needMiterLimit = true;
    }

    onLoad() {
        super.onLoad();

        this.node.on('offset-change', this.updateColorShap, this);
        this.node.on('points-change', this.updateColorShap, this);
    }

    overrideDraw(cxt: cc.Graphics, centerX: number, centerY: number) {
        const polygon = this.getComponent(shapEllipse);
        centerX += polygon.offset.x;
        centerY += polygon.offset.y;

        const points = polygon.points;

        cxt.moveTo(points[0].x + polygon.offset.x, points[0].y + polygon.offset.y)
        for (let index = 1; index < points.length; index++) {
            cxt.lineTo(points[index].x + polygon.offset.x, points[index].y + polygon.offset.y)
        }
        cxt.close()
    }
}
